import request from "../../utils/request";

// pages/personal/personal.js
let startY = 0;
let endY = 0;
let moveDistance = 0;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        coverTransform:'',
        coverTransition:'transform 1s linear',
        userInfo:{},
        recentPlaylist:[]
    },
    toLogin(){
        wx.reLaunch({
          url: '/pages/login/login',
        })
    },

    handleTouchStart(e){
        this.setData({
            coverTransition:''
        })
        startY = e.touches[0].clientY;
        // console.log('startY',startY);
    },
    handleTouchMove(e){
        endY = e.touches[0].clientY;
        moveDistance = endY-startY;

        if(moveDistance<=0){
            return;
        }
        if(moveDistance>=80){
            moveDistance=80;
        }
        this.setData({
            coverTransform:`translateY(${moveDistance}rpx)`,
        })
    },
    handleTouchEnd(){
       this.setData({
           coverTransform:'translateY(0rpx)',
           coverTransition:'transform 1s linear'
       })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let userInfo = wx.getStorageSync('userInfo');

        if(userInfo){
            this.setData({
                userInfo:JSON.parse(userInfo),
            })

            this.getRecentPlaylist(this.data.userInfo.userId);
        }
       
    },

    async getRecentPlaylist(uid){
        let recentPlaylistData = await request('/user/record',{uid,type:0});
        // console.log(recentPlaylistData);
        let index = 0;
        let recentPlaylist = recentPlaylistData.data.allData.map((item)=>{
            item.id = index++;
            return item;
        })
        // console.log(recentPlaylist);
        this.setData({
            recentPlaylist
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})